package com.ruoyi.xsyp.controller;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.xsyp.domain.Student;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.xsyp.domain.Jianli;
import com.ruoyi.xsyp.service.IJianliService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 学生简历Controller
 * 
 * @author zhangxingui
 * @date 2022-06-10
 */
@Controller
@RequestMapping("/xsyp/jianli")
public class JianliController extends BaseController
{
    private String prefix = "xsyp/jianli";

    @Autowired
    private IJianliService jianliService;

    @RequiresPermissions("xsyp:jianli:view")
    @GetMapping()
    public String jianli()
    {
        return prefix + "/jianli";
    }

    /**
     * 查询学生简历列表
     */
    @RequiresPermissions("xsyp:jianli:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Jianli jianli)
    {
        startPage();
        List<Jianli> list = jianliService.selectJianliList(jianli);
        return getDataTable(list);
    }

    /**
     * 导出学生简历列表
     */
    @RequiresPermissions("xsyp:jianli:export")
    @Log(title = "学生简历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Jianli jianli)
    {
        List<Jianli> list = jianliService.selectJianliList(jianli);
        ExcelUtil<Jianli> util = new ExcelUtil<Jianli>(Jianli.class);
        return util.exportExcel(list, "学生简历数据");
    }

    /**
     * 导入学生简历列表
     */

    @Log(title = "学生简历", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Jianli> util = new ExcelUtil<Jianli>(Jianli.class);
        List<Jianli> jianliList = util.importExcel(file.getInputStream());
        String operName = ShiroUtils.getSysUser().getLoginName();
        String message = jianliService.importJianli(jianliList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<Jianli> util = new ExcelUtil<Jianli>(Jianli.class);
        return util.importTemplateExcel("简历信息");
    }


    /**
     * 新增学生简历
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学生简历
     */
    @RequiresPermissions("xsyp:jianli:add")
    @Log(title = "学生简历", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Jianli jianli)
    {
        return toAjax(jianliService.insertJianli(jianli));
    }

    /**
     * 修改学生简历
     */
    @RequiresPermissions("xsyp:jianli:edit")
    @GetMapping("/edit/{jId}")
    public String edit(@PathVariable("jId") Long jId, ModelMap mmap)
    {
        Jianli jianli = jianliService.selectJianliByJId(jId);
        mmap.put("jianli", jianli);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生简历
     */
    @RequiresPermissions("xsyp:jianli:edit")
    @Log(title = "学生简历", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Jianli jianli)
    {
        return toAjax(jianliService.updateJianli(jianli));
    }

    /**
     * 删除学生简历
     */
    @RequiresPermissions("xsyp:jianli:remove")
    @Log(title = "学生简历", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jianliService.deleteJianliByJIds(ids));
    }
}
